export default {
  state: {
    appkey: '43fe9b8de1d5f3934eebf713',
    secret: '2032ab56604aa09b109938eb',
    JIMUserList: [],
    JIMTargetUser: {}
  },
  getters: {
    appkey: state => state.appkey,
    secret: state => state.secret,
    JIMUserList: state => state.JIMUserList,
    JIMTargetUser: state => state.JIMTargetUser
  },
  actions: {
    // JMessage初始化
    JIMInit({ state }, payload) {
      // 初始化数据  timestamp 时间戳 random_str 随机字符串 signature 签名，需md5加密
      const timestamp = (new Date()).valueOf()
      const randomStr = '022cd9fd995849b58b3ef0e943421ed9'
      const signature = md5(`appkey=${state.appkey}&timestamp=${timestamp}&random_str=${randomStr}&key=${state.secret}`)

      // 初始化
      JIM.init({
        'appkey': state.appkey,
        'random_str': randomStr,
        'signature': signature,
        'timestamp': timestamp,
        'flag': 1
      }).onSuccess(data => {
        // 初始化成功的时候，需要去进行操作
        payload.onSuccess && payload.onSuccess(data)
      })
    }
  },
  mutations: {
    setJIMUserList(state, payload) {
      state.JIMUserList = payload
    },
    setJIMTargetUser(state, payload) {
      state.JIMTargetUser = payload
    }
  }
}